var t = getApp(), e = t.requirejs('core');
Page({
  data: {
    navs: 1,
    page: 1,
    list: [],
    navindex: 1
  },
  onLoad(options) {
    this.get_add();
  },

  // 切换导航
  changenav(params) {
    this.setData({navs: params.currentTarget.dataset.index, page: 1});
    if (this.data.navs == 1) {
      this.get_add()
    } else if (this.data.navs == 2) {
      this.get_sub()
    }
  },

  // 获取增加数据
  get_add () {
    let that = this;
    e.get('zstock/kucun/get_list', {page: that.data.page, type: 1}, res => {
      console.log("增加数据");
      console.log(res)
      let list = [];
      if (that.data.page != 1) {
        list = that.data.list
      }
      res.list.forEach(item => {
        list.push(item)
      });
      this.setData({list: list});
    })
  },
  // 获取减少数据
  get_sub () {
    let that = this;
    e.get('zstock/kucun/get_list', {page: that.data.page, type: 2}, res => {
      console.log("减少数据");
      console.log(res)
      let list = [];
      if (that.data.page != 1) {
        list = that.data.list
      }
      res.list.forEach(item => {
        list.push(item)
      });
      this.setData({list: list});
    })
  },

  // 下拉刷新
  onPullDownRefresh () {
    this.setData({page: 1});
    if (this.data.navs == 1) {this.get_add()} else {this.get_sub()}
    wx.showToast({title: '刷新完毕', icon: 'none'});
    wx.stopPullDownRefresh();
  },
  // 上拉加载
  onReachBottom () {
    this.setData({page: this.data.page + 1});
    if (this.data.navs == 1) {this.get_add()} else {this.get_sub()}
  },
})